import { type } from 'os';
<!--
 * @Author: your name
 * @Date: 2021-03-16 17:01:33
 * @LastEditTime: 2021-03-22 15:16:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\warranty\warrantyStatistics\batchAudit.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('warranty.batchExamine')"
        :visible="rightVisibleEdit"
        width="600px"
        @close="()=>{$store.commit('setRightVisibleEdit',false)}"
        :close-on-click-modal='false'
        >

            <el-form ref="form" :model="form" label-width="185px" >
                <el-row :gutter="20" >
                    <el-col :span="18" :offset="0">
                        <el-form-item :label="$t('warranty.condition')" prop="condition" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-select v-model="form.condition" filterable :placeholder="$t('please_choose')"  style="width:200px;">
                                <el-option
                                    v-for="item in conditionList"
                                    :key="item.id"
                                    :label="item.text"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        
                    </el-col>
                    <el-col :span="18" :offset="0">
                        <el-form-item :label="$t('warranty.interval.day')" prop="days" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input v-model="form.days" :placeholder="$t('pleaseInput')" style="width:200px;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setRightVisibleEdit',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {
        selectDataList:{
            type:Array,
            default:()=> []
        }
    },
    data() {
        return {
            form:{
                days:'',
                condition:'1'
            },
            conditionList:[{
                text:this.$t('warranty.access.time'),
                id:'1'
            }]
        };
    },
    computed: {
        rightVisibleEdit(){
            return this.$store.state.sysStore.rightVisibleEdit
        },
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        async qualityCheckQualityBatch(){
            let rows=this.selectDataList
            if(rows.length == 0){
                this.comm.showMsg(false, this.$t('pleaseSelect'))
                return
            }
            let res = await this.API.qualityCheckQualityBatch({
                ids:rows.map(item =>{
                    return item.sid
                }),
                days:this.form.days

            })
            if(this.comm.showMsg(res.success)){
                this.$emit('uploadData',true)
                this.$store.commit('setRightVisibleEdit',false)
                const h = this.$createElement
                const newDatas = []
                for (const i in res.object) {
                    newDatas.push(h('p', null, res.object[i]))
                }
                if(res.object.length>0){
                    this.$confirm(this.$t('warranty.not.condition'),{
                        title: this.$t('warranty.not.condition'),
                        message: h('div', null, newDatas),
                    })
                    .then(_ => {
                    })
                    .catch(_ => {});
                }
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.qualityCheckQualityBatch()
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
    },
};
</script>

<style  lang="less" scoped>

</style>
